#!/bin/sh -e

setup_buffer()
{
	echo "Setup net buffer"
	echo "nproc: $(nproc), nr_threads: $nr_threads"
	local mem_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
	local mem_byte=$((mem_kb * 1024))
	local buffer_size=$((mem_byte / nr_threads / 16))
	echo "buffer_size: $buffer_size"
	echo $buffer_size > /proc/sys/net/core/wmem_max
	echo $buffer_size > /proc/sys/net/core/rmem_max
	echo $buffer_size > /proc/sys/net/core/wmem_default
	echo $buffer_size > /proc/sys/net/core/rmem_default

	modprobe sctp
	echo 4096 349500 $buffer_size > /proc/sys/net/sctp/sctp_rmem
	echo 4096 349500 $buffer_size > /proc/sys/net/sctp/sctp_wmem
}

setup_buffer
